

<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'ptproperty-form',
        'enableAjaxValidation' => true,
            ));
    ?>

    <p class="note"><?php echo Yii::t('application', 'Fields with <span class="required">*</span> are required.'); ?></p>

    <?php echo $form->errorSummary($model); ?>

    <div class="row">
        <?php echo $form->labelEx($model, 'caseno'); ?>		
        <?php echo $form->textField($model, 'caseno', array('size' => 10, 'maxlength' => 10)); ?>
        <?php echo $form->error($model, 'caseno'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'idccward'); ?>		
        <?php echo $form->textField($model, 'idccward', array('size' => 10, 'maxlength' => 10, 'ajax' => array('type' => 'POST', 'dataType' => 'json', 'data' => array('cid' => 'js:$(\'#Ptproperty_idccward\').val()',), 'url' => CController::createUrl('ccward/jsonmessage'), 'success' => 'function(data){$(\'#' . CHtml::activeId($model, 'idccward') . '_msg\').text(data.message);}'))); ?>
        <span id="<?php echo CHtml::activeId($model, 'idccward'); ?>_msg">
            <?php echo!isset($model->idccward0->idcczone) || $model->isNewRecord ? "-" : $model->idccward0->idcczone; ?>
        </span>
        <?php
        $imghtml = CHtml::image(Yii::app()->request->baseUrl . '/images/tooltip.png');
        echo CHtml::link($imghtml, "", array(
            'style' => 'cursor: pointer; text-decoration: underline;',
            'onclick' => "{popupview('idccward', 'index.php?r=ccward/popupview'); }"));
        ?>
        <?php echo $form->error($model, 'idccward'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'idccsex'); ?>		
        <?php echo $form->textField($model, 'idccsex', array('size' => 10, 'maxlength' => 10, 'ajax' => array('type' => 'POST', 'dataType' => 'json', 'data' => array('cid' => 'js:$(\'#Ptproperty_idccsex\').val()',), 'url' => CController::createUrl('ccsex/jsonmessage'), 'success' => 'function(data){$(\'#' . CHtml::activeId($model, 'idccsex') . '_msg\').text(data.message);}'))); ?>
        <span id="<?php echo CHtml::activeId($model, 'idccsex'); ?>_msg">
            <?php echo!isset($model->idccsex0->sexname) || $model->isNewRecord ? "-" : $model->idccsex0->sexname; ?>
        </span>
        <?php
        $imghtml = CHtml::image(Yii::app()->request->baseUrl . '/images/tooltip.png');
        echo CHtml::link($imghtml, "", array(
            'style' => 'cursor: pointer; text-decoration: underline;',
            'onclick' => "{popupview('idccsex', 'index.php?r=ccsex/popupview'); }"));
        ?>
        <?php echo $form->error($model, 'idccsex'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'idptexsumptor'); ?>		
        <?php echo $form->textField($model, 'idptexsumptor', array('size' => 10, 'maxlength' => 10, 'ajax' => array('type' => 'POST', 'dataType' => 'json', 'data' => array('cid' => 'js:$(\'#Ptproperty_idptexsumptor\').val()',), 'url' => CController::createUrl('ptexsumptor/jsonmessage'), 'success' => 'function(data){$(\'#' . CHtml::activeId($model, 'idptexsumptor') . '_msg\').text(data.message);}'))); ?>
        <span id="<?php echo CHtml::activeId($model, 'idptexsumptor'); ?>_msg">
            <?php echo!isset($model->idptexsumptor0->type) || $model->isNewRecord ? "-" : $model->idptexsumptor0->type; ?>
        </span>
        <?php
        $imghtml = CHtml::image(Yii::app()->request->baseUrl . '/images/tooltip.png');
        echo CHtml::link($imghtml, "", array(
            'style' => 'cursor: pointer; text-decoration: underline;',
            'onclick' => "{popupview('idptexsumptor', 'index.php?r=ptexsumptor/popupview'); }"));
        ?>
        <?php echo $form->error($model, 'idptexsumptor'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'ownername'); ?>		
        <?php echo $form->textField($model, 'ownername', array('size' => 60, 'maxlength' => 100)); ?>
        <?php echo $form->error($model, 'ownername'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'owneraddress'); ?>		
        <?php echo $form->textField($model, 'owneraddress', array('size' => 60, 'maxlength' => 100)); ?>
        <?php echo $form->error($model, 'owneraddress'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'propertyno'); ?>		
        <?php echo $form->textField($model, 'propertyno', array('size' => 45, 'maxlength' => 45)); ?>
        <?php echo $form->error($model, 'propertyno'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'propertyaddress'); ?>		
        <?php echo $form->textField($model, 'propertyaddress', array('size' => 60, 'maxlength' => 100)); ?>
        <?php echo $form->error($model, 'propertyaddress'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'constyear'); ?>		
        <?php echo $form->textField($model, 'constyear', array('size' => 10, 'maxlength' => 10)); ?>
        <?php echo $form->error($model, 'constyear'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'totalplotarea'); ?>		
        <?php echo $form->textField($model, 'totalplotarea', array('size' => 15, 'maxlength' => 15)); ?>
        <?php echo $form->error($model, 'totalplotarea'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'openplotarea'); ?>		
        <?php echo $form->textField($model, 'openplotarea', array('size' => 15, 'maxlength' => 15)); ?>
        <?php echo $form->error($model, 'openplotarea'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'compplotarea'); ?>		
        <?php echo $form->textField($model, 'compplotarea', array('size' => 15, 'maxlength' => 15)); ?>
        <?php echo $form->error($model, 'compplotarea'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'transferbreakupflag'); ?>		
        <?php echo $form->textField($model, 'transferbreakupflag'); ?>
        <?php echo $form->error($model, 'transferbreakupflag'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'deleteflag'); ?>		
        <?php echo $form->textField($model, 'deleteflag'); ?>
        <?php echo $form->error($model, 'deleteflag'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'waterharvesting'); ?>		
        <?php echo $form->textField($model, 'waterharvesting'); ?>
        <?php echo $form->error($model, 'waterharvesting'); ?>
    </div>

    <div class="row">
        <?php //echo $form->labelEx($model, 'propertydetails'); ?>		
        <?php //echo $form->textArea($model, 'propertydetails', array('rows' => 6, 'cols' => 50)); ?>
        <?php //echo $form->error($model, 'propertydetails'); ?>
    </div>

    <?php
//    echo CHtml::activeTextField($data['aresidential']);
    $columns = array(
        array(
            'name' => 'id',
            'value' => 'CHtml::hiddenField("propertydetails[" . $data[\'id\'] . "][id]", $data[\'id\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
            'headerHtmlOptions' => array('style' => 'display:none'),
            'htmlOptions' => array('style' => 'display:none'),
        ),
        array(
            'name' => 'category',
            'value' => 'CHtml::hiddenField("propertydetails[" . $data[\'id\'] . "][category]", $data[\'category\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
            'headerHtmlOptions' => array('style' => 'display:none'),
            'htmlOptions' => array('style' => 'display:none'),
        ),
        array(
            'header' => Yii::t('application', 'Category'),
            'name' => 'category',
            'value' => '$data[\'category\']',
            'htmlOptions' => array('style' => 'font-weight: bold;'),
        ),
        array(
            'header' => Yii::t('application', 'Aresidential'),
            'name' => 'aresidential',
            'value' => 'CHtml::textField("propertydetails[" . $data[\'id\'] . "][aresidential]", $data[\'aresidential\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
        ),
        array(
            'header' => Yii::t('application', 'Acommerical'),
            'name' => 'acommercial',
            'value' => 'CHtml::textField("propertydetails[" . $data[\'id\'] . "][acommercial]", $data[\'acommercial\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
        ),
        array(
            'header' => Yii::t('application', 'Bresidential'),
            'name' => 'bresidential',
            'value' => 'CHtml::textField("propertydetails[" . $data[\'id\'] . "][bresidential]", $data[\'bresidential\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
        ),
        array(
            'header' => Yii::t('application', 'Bcommerical'),
            'name' => 'bcommercial',
            'value' => 'CHtml::textField("propertydetails[" . $data[\'id\'] . "][bcommercial]", $data[\'bcommercial\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
        ),
        array(
            'header' => Yii::t('application', 'Cresidential'),
            'name' => 'cresidential',
            'value' => 'CHtml::textField("propertydetails[" . $data[\'id\'] . "][cresidential]", $data[\'cresidential\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
        ),
        array(
            'header' => Yii::t('application', 'Ccommerical'),
            'name' => 'ccommercial',
            'value' => 'CHtml::textField("propertydetails[" . $data[\'id\'] . "][ccommercial]", $data[\'ccommercial\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
        ),
        array(
            'header' => Yii::t('application', 'Dresidential'),
            'name' => 'dresidential',
            'value' => 'CHtml::textField("propertydetails[" . $data[\'id\'] . "][dresidential]", $data[\'dresidential\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
        ),
        array(
            'header' => Yii::t('application', 'Dcommerical'),
            'name' => 'dcommercial',
            'value' => 'CHtml::textField("propertydetails[" . $data[\'id\'] . "][dcommercial]", $data[\'dcommercial\'], array(\'width\'=>20,\'size\'=>7,\'maxlength\'=>30,\'style\'=>\'text-align:right\'))',
            'type' => 'raw',
        ),
    );

    $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'area-grid',
        'dataProvider' => $dataProvider,
        'columns' => $columns,
        'enablePagination' => false,
        'summaryText' => '',
//        'filter' => $filtersForm,
    ));
    ?>


    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('application', 'Create') : Yii::t('application', 'Save')); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog
    'id' => 'dialog' . get_class($model) . '_idccsex',
    'options' => array(
        'title' => Yii::t('application', 'Ccsexes'),
        'autoOpen' => false,
        'modal' => true,
        'width' => 550,
        'height' => 470,
    ),
));
?>
<div class="divforidccsex"></div>
<?php $this->endWidget(); ?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog
    'id' => 'dialog' . get_class($model) . '_idccward',
    'options' => array(
        'title' => Yii::t('application', 'Ccwards'),
        'autoOpen' => false,
        'modal' => true,
        'width' => 550,
        'height' => 470,
    ),
));
?>
<div class="divforidccward"></div>
<?php $this->endWidget(); ?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog
    'id' => 'dialog' . get_class($model) . '_idptexsumptor',
    'options' => array(
        'title' => Yii::t('application', 'Ptexsumptors'),
        'autoOpen' => false,
        'modal' => true,
        'width' => 550,
        'height' => 470,
    ),
));
?>
<div class="divforidptexsumptor"></div>
<?php $this->endWidget(); ?>

<script type="text/javascript">
    function popupview(id, url)
    {
        jQuery.ajax({'url':url,'data':'isAjaxRequest=1&id=<?php echo get_class($model); ?>_' + id,'type':'post','dataType':'json','success':function(data)
            {
                $('#dialog<?php echo get_class($model); ?>_' + id +' div.divfor' + id).html(data.div);
            } ,'cache':false});
        $('#dialog<?php echo get_class($model); ?>_' + id).dialog('open');
        return false;
    }
    
    function refreshTotal(){
        sum = 0;
        for(i=0; i<=5; i++){
            sum += parseFloat($('#propertydetails_' + i + '_aresidential').val());
        }
        $('#propertydetails_6_aresidential').val(sum);
        sum = 0;
        for(i=0; i<=5; i++){
            sum += parseFloat($('#propertydetails_' + i + '_acommercial').val());
        }
        $('#propertydetails_6_acommercial').val(sum);

        sum = 0;
        for(i=0; i<=5; i++){
            sum += parseFloat($('#propertydetails_' + i + '_bresidential').val());
        }
        $('#propertydetails_6_bresidential').val(sum);
        sum = 0;
        for(i=0; i<=5; i++){
            sum += parseFloat($('#propertydetails_' + i + '_bcommercial').val());
        }
        $('#propertydetails_6_bcommercial').val(sum);

        sum = 0;
        for(i=0; i<=5; i++){
            sum += parseFloat($('#propertydetails_' + i + '_cresidential').val());
        }
        $('#propertydetails_6_cresidential').val(sum);
        sum = 0;
        for(i=0; i<=5; i++){
            sum += parseFloat($('#propertydetails_' + i + '_ccommercial').val());
        }
        $('#propertydetails_6_ccommercial').val(sum);

        sum = 0;
        for(i=0; i<=5; i++){
            sum += parseFloat($('#propertydetails_' + i + '_dresidential').val());
        }
        $('#propertydetails_6_dresidential').val(sum);
        sum = 0;
        for(i=0; i<=5; i++){
            sum += parseFloat($('#propertydetails_' + i + '_dcommercial').val());
        }
        $('#propertydetails_6_dcommercial').val(sum);
    }
    
    refreshTotal();
    
    $('input[id^="propertydetails_"]').change(function() {
        refreshTotal();
    });   
    
    $('input[id^="propertydetails_6_"]').attr('readonly','readonly');


    $(document).ready(function() {
        //        $('input[id^="propertydetails_"]').keydown(function(event) {
        //            // Allow: backspace, delete, tab and escape
        //            if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || 
        //                // Allow: Ctrl+A
        //            (event.keyCode == 65 && event.ctrlKey === true) || 
        //                // Allow: home, end, left, right
        //            (event.keyCode >= 35 && event.keyCode <= 39)) {
        //                // let it happen, don't do anything
        //                return;
        //            }
        //            else {
        //                // Ensure that it is a number and stop the keypress
        //                if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
        //                    event.preventDefault(); 
        //                }   
        //            }
        //        });

        $('input[id^="propertydetails_"]').keydown(function(event) {
            // Backspace, tab, enter, end, home, left, right,decimal(.)in number part, decimal(.) in alphabet
            // We don't support the del key in Opera because del == . == 46.
            var controlKeys = [8, 9, 13, 35, 36, 37, 39,110,190];
            // IE doesn't support indexOf
            var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
            // Some browsers just don't raise events for control keys. Easy.
            // e.g. Safari backspace.
            if (!event.which || // Control keys in most browsers. e.g. Firefox tab is 0
            (49 <= event.which && event.which <= 57) || // Always 1 through 9
            (96 <= event.which && event.which <= 106) || // Always 1 through 9 from number section 
            (48 == event.which && $(this).attr("value")) || // No 0 first digit
            (96 == event.which && $(this).attr("value")) || // No 0 first digit from number section
            isControlKey) { // Opera assigns values for control keys.
                return;
            } else {
                event.preventDefault();
            }
        });

    });


</script>
